:- include('setting_water_jug.pl').


        path:-
        	not(open(_)),!,
        	write('No solution'), nl.
        path:-
        	checkGoal.

        path:-
        	open(State),
        	retract(open(State)),
		mywrite(State), nl,
        	assert(closed(State)),
        	get_children(State), !,
	path.
        
       checkGoal:-
	      open(State), !,
		isGoal(State),
		mywrite(State), nl,
	    	write('Solution found'),
	       	get_char(_).


        get_children(State):-
          	moves(State,Child),
		addToOpen(Child), fail.
        get_children(_).

	addToOpen(State):-
		algorithm(AL),
		AL == dfs,
		asserta(open(State)) ;
		algorithm(AL),
		AL == brfs,
		assertz(open(State)).
		
          
        moves(Parent, Next):-
        	move(Parent, Next),
        	not(open(Next)),
        	not(closed(Next)).
	
        go:-
             	retractall(open(_)), 
             	retractall(closed(_)),
			go_p(Start), 
             	assertz(open(Start)),
             	path.
